<?php
require_once('config.hotel.php');
/** 
 * 有关景区的参数设置
 */
//require_once('config.mgafinstall.php');

class Hotel_hotelController extends Gaf_Controller_Action {
	private $hotel;
	public function init(){
		parent::init();
		$this->hotel=new hotel();
	}
	/**
	 * @name 酒店管理
	 * @menu 酒店管理/酒店列表
	 * @comment 酒店管理，设置酒店参数。
	 * @type WEB
	 */
	public function indexAction(){
		$p=$this->_getParam("p","0");
		$this->view->MsgSection=$this->_getParam('errmsg');
		$hlist=$this->hotel->getHotelList();
		$this->view->hlist=$hlist;
		$this->view->page=$p;
	}
	/**
	 * @name 新增酒店
	 * @comment 新增酒店
	 */
	public function addhotelAction(){
		$rlist=$this->hotel->getRegionByLevel();
		$scelist=$this->hotel->getScenicList();
		$this->view->rlist=$rlist;
		$this->view->scelist=$scelist;
	}
	/**
	 *@name 新增酒店动作
	 *@comment 新增酒店 
	 */
	public function doaddhotelAction(){
		$this->_helper->viewRenderer->setNoRender();
		$paramArr['name']=$name=$this->_getParam('name');
		$paramArr['sid']=$sid=$this->_getParam('sid');
		$paramArr['hotellevel']=$hotellevel=$this->_getParam('hotellevel');
		$paramArr['preday']=$preda=$this->_getParam('preday');
		$paramArr['hoteldetail']=$hoteldetail=$this->_getParam('hoteldetail');
		$paramArr['hotelfeature']=$hotelfearture=$this->_getParam('hotelfeature');
		$paramArr['addr']=$addr=$this->_getParam('addr');
		$paramArr['evaluation']=$evaluation=$this->_getParam('evaluation');
		$paramArr['recommend']=$recommend=$this->_getParam('recommend');
		
		$paramArr['district']=$district=$this->_getParam('district');
		$paramArr['city']=$city=$this->_getParam('city');
		$paramArr['province']=$province=$this->_getParam('province');
		$paramArr['area']=$area=$this->_getParam('area');
		$paramArr['foreign']=$foreign=$this->_getParam('foreign');
		
		$this->hotel->addHotel($paramArr);
	}
	/**
	 * @name 查看修改酒店
	 * @comment 查看修改酒店
	*/
	public function gethotelAction(){
		$hotelid=$this->_getParam('hotelid');
		$hotel=$this->hotel->getHotelById($hotelid);
		//print_r($hotel);
		$scelist=$this->hotel->getScenicList();
		$arr['sid']=-1;
		$arr['name']="---";
		array_unshift($scelist,$arr);
		foreach ($scelist as &$sc){
			if($sc['sid']==$hotel['sid'])	$sc['sel']="selected";
			else $sc['sel']="";
		}
		$reg2hotel=$this->hotel->getRegion2Hotel($hotelid);
		$rslist=$this->hotel->getRegionByLevel();
		foreach ($rslist as &$r){
			$r['sel']='';
			foreach ($reg2hotel as $rg){
				if($r['rid']==$rg['rid'])	$r['sel']="selected";
				else if($r['sel']!='selected') $r['sel']='';
			}
		}
		//echo "<pre>";
		//print_r($rslist);
		$this->view->hotel=$hotel;
		$this->view->scelist=$scelist;
		$this->view->rslist=$rslist;
	}
	/**
	 * @name 修改酒店信息
	 * @comment 修改酒店信息
	*/
	public function edithotelAction(){
		$hotelid=$this->_getParam('hotelid');
		$paramArr['name']=$name=$this->_getParam('name');
		$paramArr['sid']=$sid=$this->_getParam('sid');
		$paramArr['hotellevel']=$hotellevel=$this->_getParam('hotellevel');
		$paramArr['hoteldetail']=$hoteldetail=$this->_getParam('hoteldetail');
		$paramArr['hotelfeature']=$hotelfearture=$this->_getParam('hotelfeature');
		$paramArr['addr']=$addr=$this->_getParam('addr');
		$paramArr['evaluation']=$evaluation=$this->_getParam('evaluation');
		$paramArr['recommend']=$recommend=$this->_getParam('recommend');
		
		$paramArr['district']=$district=$this->_getParam('district');
		$paramArr['city']=$city=$this->_getParam('city');
		$paramArr['province']=$province=$this->_getParam('province');
		$paramArr['area']=$area=$this->_getParam('area');
		$paramArr['foreign']=$foreign=$this->_getParam('foreign');
		
		$ret=$this->hotel->editHotelById($hotelid,$paramArr);
		if($ret)	$this->_redirect("/hotel/hotel/index?errmsg=修改成功");
		else $this->_redirect("/hotel/hotel/index?errmsg=修改失败");
	}
	/**
	* @name 删除酒店
	* @comment 删除酒店 
	*/
	public function delhotelAction(){
		$this->_helper->viewRenderer->setNoRender();
		$hotelid=$this->_getParam('hotelid');
		$p=$this->_getParam("p","0");
		$this->hotel->delHotel($hotelid);
		$this->_redirect("/hotel/hotel/index?errmsg=删除成功");
	}
	/**
	 * @name 添加酒店客房类型
	 * @comment 添加酒店客房类型
	*/
	public function addhotelroomAction(){
		$hotelid=$this->_getParam('hotelid');
		$p=$this->_getParam("p","0");
		$this->view->MsgSection=$this->_getParam('errmsg');
		$hotel=$this->hotel->getHotelById($hotelid);
		$roomList=$this->hotel->getRoomTypeByHotel($hotelid);
		$this->view->hotelid=$hotelid;
		$this->view->hotel=$hotel;
		$this->view->roomList=$roomList;
		$this->view->page=$p;
	}
	/**
	 * @name 添加客房信息 
	 * @comment 添加客房信息
	*/
	public function doaddroomAction(){
		$this->_helper->viewRenderer->setNoRender();
		$param['hotelid']=$hotelid=$this->_getParam('hotelid');
		$param['price']=$price=$this->_getParam('price');
		$param['pricetype']=$pricetype=$this->_getParam('pricetype');
		$param['roomtype']=$roomtype=$this->_getParam('roomtype');
		$param['roomnum']=$roomnum=$this->_getParam('roomnum');
		$param['memo']=$memo=$this->_getParam('roomdetail');
		$this->hotel->addRoomType($param);
		$this->_redirect("/hotel/hotel/addhotelroom?hotelid=$hotelid&errmsg=添加成功");
	}
	/**
	 * @name 删除客房
	 * @comment 删除客房
	*/
	public function delroomAction(){
		$this->_helper->viewRenderer->setNoRender();
		$hotelid=$this->_getParam('hotelid');
	
		$id=$this->_getParam('id');
		$this->hotel->delRoom($id);
	 	$this->_redirect("/hotel/hotel/addhotelroom?hotelid=$hotelid&errmsg=删除成功");
	}
	/**
	 * @name 获取客房信息
	 * @comment 客房信息
	*/
	public function getroomAction(){
		$id=$this->_getParam('id');
		$room=$this->hotel->getRoomById($id);
		$this->view->room=$room;
	}
	public function editroomAction(){
		$id=$this->_getParam('id');
		$hotelid=$this->_getParam('hotelid');
		$paramArr['roomtype']=$roomtype=$this->_getParam('roomtype');
		$paramArr['roomnum']=$roomnum=$this->_getParam('roomnum');
		$paramArr['pricetype']=$pricetype=$this->_getParam('pricetype');
		$paramArr['price']=$price=$this->_getParam('price');
		$paramArr['memo']=$roomdetail=$this->_getParam('roomdetail');
		$ret=$this->hotel->editRoom($id,$paramArr);
		if($ret)	$this->_redirect("/hotel/hotel/addhotelroom?hotelid=$hotelid&errmsg=修改成功");
		else $this->_redirect("/hotel/hotel/addhotelroom?hotelid=$hotelid&errmsg=修改失败");
	}
	public function addgalleryAction(){
		
	}
}